Load all required libraries.

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.6     v dplyr   1.0.8
## v tidyr   1.2.0     v stringr 1.4.0
## v readr   2.1.2     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(broom)

Read in raw data from RDS.

raw_data <- readRDS("./n1_n2_cleaned_cases.rds")

Make a few small modifications to names and data for visualizations.

final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
  rename(Facility = wrf) %>%
  mutate(Facility = recode(Facility, 
                           "NO" = "WRF A",
                           "MI" = "WRF B",
                           "CC" = "WRF C"))

Seperate the data by gene target to ease layering in the final plot

#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>% 
  select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
  group_by(date) %>% summarise_if(is.numeric, mean)

#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]

only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]

Build the main plot

      #first layer is the background epidemic curve
        p1 <- only_background %>%
              plotly::plot_ly() %>%
              plotly::add_trace(x = ~date, y = ~new_cases_clarke, 
                                type = "bar", 
                                hoverinfo = "text",
                                text = ~paste('</br> Date: ', date,
                                                     '</br> Daily Cases: ', new_cases_clarke),
                                alpha = 0.5,
                                name = "Daily Reported Cases",
                                color = background_color,
                                colors = background_color,
                                showlegend = FALSE) %>%
            layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
            layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
        
        #renders the main plot layer two as seven day moving average
        p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke, 
                             type = "scatter",
                             mode = "lines",
                             hoverinfo = "text",
                            text = ~paste('</br> Date: ', date,
                                                     '</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
                             name = "Seven Day Moving Average Athens",
                             line = list(color = seven_day_ave_color),
                             showlegend = FALSE)
      

        
        #renders the main plot layer three as positive target hits
        
        p2 <- plotly::plot_ly() %>%
          plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
                                       type = "scatter",
                                       mode = "markers",
                                       hoverinfo = "text",
                                       text = ~paste('</br> Date: ', date,
                                                     '</br> Facility: ', Facility,
                                                     '</br> Target: ', target,
                                                     '</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
                                       data = only_n1,
                                       symbol = ~Facility,
                                       marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
                                       showlegend = FALSE) %>%
          plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
                                       type = "scatter",
                                       mode = "markers",
                                       hoverinfo = "text",
                                       text = ~paste('</br> Date: ', date,
                                                     '</br> Facility: ', Facility,
                                                     '</br> Target: ', target,
                                                     '</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
                                       data = only_n2,
                                       symbol = ~Facility,
                                       marker = list(color = '#D95F02', size = 8, opacity = 0.65),
                                       showlegend = FALSE) %>%
            layout(yaxis = list(title = "SARS CoV-2 Copies/L", 
                                 showline = TRUE,
                                 type = "log",
                                 dtick = 1,
                                 automargin = TRUE)) %>%
            layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
        
        #adds the limit of detection dashed line
        p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"), 
                                          xend = ~max(date + 10), 
                                          y = 3571.429, yend = 3571.429,
                                          opacity = 0.35,
                                          line = list(color = "black", dash = "dash")) %>%
          layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y", 
                                    text = "Limit of Detection", showarrow = FALSE))

        

        p1
        p2

Combine the two main plot pieces as a subplot

#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")

#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")


#rejoin the old data frames then seperate in to averages for each plant. 
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
  select(c(date, mean_total_copies)) %>%
  group_by(date) %>%
  summarize_if(is.numeric, mean) %>%
  ungroup() %>%
  mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
  select(c(date, mean_total_copies)) %>%
  group_by(date) %>%
  summarize_if(is.numeric, mean) %>%
  ungroup() %>%
  mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
  select(c(date, mean_total_copies)) %>%
  group_by(date) %>%
  summarize_if(is.numeric, mean) %>%
  ungroup() %>%
  mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)

Build loess smoothing figures figures

This makes the individual plots

#**************************************WRF A PLOT**********************************************
#add trendlines 
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) + 
  stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77', 
              span = 0.25, n = 814)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'

fit_botha
##   [1] 13.05480 13.04990 13.04506 13.04028 13.03555 13.03088 13.02626 13.02170
##   [9] 13.01719 13.01273 13.00833 13.00398 12.99967 12.99542 12.99122 12.98707
##  [17] 12.98296 12.97890 12.97489 12.97093 12.96701 12.96313 12.95930 12.95551
##  [25] 12.95177 12.94806 12.94440 12.94078 12.93720 12.93366 12.93015 12.92669
##  [33] 12.92326 12.91987 12.91651 12.91319 12.90991 12.90665 12.90343 12.90025
##  [41] 12.89709 12.89397 12.89088 12.88782 12.88480 12.88182 12.87889 12.87599
##  [49] 12.87314 12.87034 12.86758 12.86488 12.86222 12.85961 12.85705 12.85455
##  [57] 12.85210 12.84971 12.84737 12.84509 12.84287 12.84070 12.83860 12.83657
##  [65] 12.83459 12.83268 12.83084 12.82906 12.82736 12.82572 12.82415 12.82266
##  [73] 12.82124 12.81989 12.81862 12.81743 12.81631 12.81528 12.81432 12.81345
##  [81] 12.81265 12.81195 12.81133 12.81079 12.81034 12.80997 12.80963 12.80935
##  [89] 12.80912 12.80893 12.80880 12.80871 12.80868 12.80870 12.80877 12.80889
##  [97] 12.80906 12.80929 12.80957 12.80990 12.81029 12.81073 12.81123 12.81179
## [105] 12.81240 12.81306 12.81379 12.81457 12.81541 12.81631 12.81727 12.81829
## [113] 12.81936 12.82050 12.82170 12.82296 12.82428 12.82566 12.82711 12.82862
## [121] 12.83019 12.83183 12.83353 12.83530 12.83713 12.83903 12.84100 12.84303
## [129] 12.84513 12.84729 12.84953 12.85183 12.85421 12.85746 12.86231 12.86859
## [137] 12.87614 12.88479 12.89439 12.90477 12.91578 12.92726 12.93903 12.95094
## [145] 12.96283 12.97454 12.98591 12.99677 13.00697 13.01634 13.02472 13.03195
## [153] 13.03787 13.04232 13.04684 13.05301 13.06069 13.06973 13.08001 13.09139
## [161] 13.10373 13.11690 13.13075 13.14516 13.15998 13.17509 13.19034 13.20559
## [169] 13.22072 13.23559 13.25006 13.26399 13.27724 13.28969 13.30119 13.31162
## [177] 13.32082 13.32867 13.33503 13.33977 13.34274 13.34382 13.34375 13.34338
## [185] 13.34270 13.34170 13.34038 13.33872 13.33672 13.33437 13.33167 13.32860
## [193] 13.32515 13.32133 13.31711 13.31250 13.30749 13.30206 13.29621 13.28994
## [201] 13.28322 13.27607 13.26846 13.26039 13.25186 13.24284 13.23335 13.22336
## [209] 13.21288 13.20189 13.18916 13.17363 13.15555 13.13515 13.11267 13.08835
## [217] 13.06244 13.03517 13.00678 12.97752 12.94761 12.91731 12.88686 12.85648
## [225] 12.82643 12.79695 12.76826 12.74062 12.71426 12.68943 12.66636 12.64529
## [233] 12.62646 12.60787 12.58745 12.56541 12.54195 12.51728 12.49159 12.46507
## [241] 12.43794 12.41039 12.38262 12.35483 12.32722 12.30000 12.27335 12.24748
## [249] 12.22260 12.19890 12.17658 12.15584 12.13688 12.11990 12.10464 12.09065
## [257] 12.07784 12.06612 12.05541 12.04562 12.03666 12.02846 12.02091 12.01394
## [265] 12.00746 12.00138 11.99562 11.99009 11.98470 11.97936 11.97400 11.96852
## [273] 11.96284 11.95687 11.95053 11.94372 11.93637 11.92838 11.91968 11.91016
## [281] 11.90075 11.89234 11.88485 11.87816 11.87219 11.86683 11.86199 11.85757
## [289] 11.85347 11.84959 11.84584 11.84212 11.83833 11.83437 11.83014 11.82556
## [297] 11.82051 11.81490 11.80863 11.80161 11.79374 11.78480 11.77471 11.76360
## [305] 11.75160 11.73883 11.72542 11.71149 11.69717 11.68258 11.66785 11.65310
## [313] 11.63847 11.62407 11.61003 11.59647 11.58352 11.57131 11.55996 11.54960
## [321] 11.54035 11.53234 11.52569 11.52053 11.51509 11.50768 11.49856 11.48798
## [329] 11.47616 11.46338 11.44986 11.43586 11.42162 11.40739 11.39341 11.37994
## [337] 11.36722 11.35549 11.34500 11.33600 11.32873 11.32345 11.32039 11.31981
## [345] 11.32194 11.32623 11.33188 11.33884 11.34702 11.35637 11.36681 11.37828
## [353] 11.39070 11.40400 11.41813 11.43300 11.44854 11.46470 11.48140 11.49857
## [361] 11.51615 11.53405 11.55222 11.57059 11.58908 11.60763 11.62617 11.64462
## [369] 11.66293 11.68102 11.69882 11.71626 11.73560 11.75889 11.78573 11.81572
## [377] 11.84848 11.88361 11.92072 11.95941 11.99929 12.03996 12.08104 12.12212
## [385] 12.16283 12.20275 12.24150 12.27868 12.31391 12.34678 12.37691 12.40390
## [393] 12.42735 12.44688 12.46518 12.48507 12.50634 12.52879 12.55218 12.57632
## [401] 12.60098 12.62596 12.65104 12.67601 12.70065 12.72475 12.74810 12.77049
## [409] 12.79170 12.81151 12.82973 12.84612 12.86048 12.87260 12.88226 12.88978
## [417] 12.89571 12.90016 12.90324 12.90506 12.90574 12.90539 12.90412 12.90205
## [425] 12.89928 12.89594 12.89213 12.88797 12.88357 12.87904 12.87450 12.87006
## [433] 12.86583 12.86193 12.85846 12.85554 12.85174 12.84564 12.83744 12.82730
## [441] 12.81539 12.80191 12.78702 12.77090 12.75372 12.73567 12.71692 12.69764
## [449] 12.67801 12.65821 12.63841 12.61880 12.59954 12.58081 12.56279 12.54566
## [457] 12.52959 12.51476 12.50134 12.48951 12.47946 12.47134 12.46316 12.45294
## [465] 12.44092 12.42732 12.41239 12.39635 12.37943 12.36186 12.34389 12.32573
## [473] 12.30762 12.28980 12.27250 12.25594 12.24036 12.22600 12.21307 12.20183
## [481] 12.19249 12.18529 12.18047 12.17732 12.17499 12.17342 12.17256 12.17239
## [489] 12.17284 12.17388 12.17547 12.17756 12.18010 12.18305 12.18637 12.19001
## [497] 12.19393 12.19809 12.20244 12.20693 12.21153 12.21619 12.22086 12.22550
## [505] 12.23007 12.23452 12.24025 12.24855 12.25919 12.27196 12.28664 12.30302
## [513] 12.32088 12.34001 12.36018 12.38118 12.40279 12.42481 12.44700 12.46916
## [521] 12.49107 12.51251 12.53326 12.55312 12.57185 12.58926 12.60511 12.61919
## [529] 12.63130 12.64120 12.64869 12.65354 12.65719 12.66116 12.66541 12.66989
## [537] 12.67453 12.67930 12.68414 12.68900 12.69383 12.69857 12.70318 12.70760
## [545] 12.71179 12.71568 12.71923 12.72239 12.72511 12.72733 12.72900 12.73007
## [553] 12.73050 12.73022 12.72919 12.72736 12.72467 12.72108 12.71652 12.71096
## [561] 12.70434 12.69660 12.68669 12.67377 12.65815 12.64011 12.61997 12.59801
## [569] 12.57454 12.54985 12.52424 12.49800 12.47145 12.44487 12.41856 12.39282
## [577] 12.36794 12.34424 12.32199 12.30151 12.28309 12.26703 12.25362 12.24032
## [585] 12.22452 12.20645 12.18632 12.16435 12.14074 12.11572 12.08950 12.06230
## [593] 12.03434 12.00582 11.97697 11.94799 11.91912 11.89055 11.86251 11.83522
## [601] 11.80888 11.78372 11.75995 11.73778 11.71743 11.69913 11.68307 11.66948
## [609] 11.65858 11.64931 11.64048 11.63209 11.62417 11.61671 11.60973 11.60324
## [617] 11.59724 11.59174 11.58676 11.58230 11.57837 11.57498 11.57215 11.56987
## [625] 11.56816 11.56702 11.56647 11.56652 11.56717 11.56844 11.57129 11.57657
## [633] 11.58409 11.59365 11.60506 11.61814 11.63270 11.64853 11.66546 11.68329
## [641] 11.70183 11.72089 11.74029 11.75982 11.77930 11.79854 11.81735 11.83553
## [649] 11.85290 11.86927 11.88444 11.89823 11.91044 11.92258 11.93618 11.95114
## [657] 11.96732 11.98461 12.00290 12.02205 12.04195 12.06249 12.08353 12.10497
## [665] 12.12668 12.14854 12.17043 12.19224 12.21383 12.23510 12.25592 12.27618
## [673] 12.29575 12.31451 12.33234 12.34913 12.36476 12.37909 12.39203 12.40429
## [681] 12.41667 12.42914 12.44168 12.45425 12.46683 12.47937 12.49186 12.50426
## [689] 12.51654 12.52868 12.54064 12.55239 12.56390 12.57514 12.58609 12.59671
## [697] 12.60697 12.61684 12.62629 12.63530 12.64383 12.65185 12.65935 12.66634
## [705] 12.67288 12.67899 12.68471 12.69007 12.69512 12.69989 12.70441 12.70873
## [713] 12.71287 12.71687 12.72078 12.72463 12.72844 12.73227 12.73614 12.74010
## [721] 12.74417 12.74839 12.75281 12.75726 12.76157 12.76573 12.76975 12.77364
## [729] 12.77739 12.78100 12.78449 12.78785 12.79108 12.79420 12.79719 12.80007
## [737] 12.80283 12.80548 12.80803 12.81046 12.81280 12.81503 12.81717 12.81920
## [745] 12.82115 12.82301 12.82477 12.82646 12.82806 12.82956 12.83094 12.83219
## [753] 12.83331 12.83431 12.83517 12.83589 12.83648 12.83692 12.83722 12.83738
## [761] 12.83739 12.83724 12.83695 12.83649 12.83588 12.83510 12.83416 12.83306
## [769] 12.83178 12.83034 12.82871 12.82691 12.82494 12.82280 12.82050 12.81803
## [777] 12.81540 12.81262 12.80969 12.80662 12.80340 12.80004 12.79655 12.79292
## [785] 12.78917 12.78529 12.78129 12.77718 12.77295 12.76861 12.76417 12.75961
## [793] 12.75493 12.75012 12.74519 12.74013 12.73494 12.72962 12.72417 12.71860
## [801] 12.71289 12.70704 12.70107 12.69495 12.68871 12.68232 12.67580 12.66914
## [809] 12.66234 12.65540 12.64831 12.64109 12.63372 12.62620
#assign fits to a vector
both_trenda <- fit_botha

#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax

#reassign dataframes (just to be safe)
work_botha <- wrfa_both

#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date

#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
  plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
                    data = smooth_frame_botha,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_botha,
                                  '</br> Median Log Copies: ', round(both_trenda, digits = 2)),
                    line = list(color = '#1B9E77', size = 8, opacity = 0.65),
                    showlegend = FALSE) %>%
     layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
                    showlegend = FALSE,
                    opacity = 0.25,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
                                  '</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
                                  '</br> Min Log Copies: ', round(both_ymina, digits = 2)),
                    name = "",
                    fillcolor = '#1B9E77',
                    line = list(color = '#1B9E77')) %>%
                layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies", 
                                 showline = TRUE,
                                 automargin = TRUE)) %>%
                layout(xaxis = list(title = "Date")) %>%
                layout(title = "WRF A") %>%
  plotly::add_markers(x = ~date, y = ~log_total_copies_both,
                      data = wrfa_both,
                       hoverinfo = "text",
                       showlegend = FALSE,
                       text = ~paste('</br> Date: ', date, 
                                     '</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
                       marker = list(color = '#1B9E77', size = 6, opacity = 0.65))

p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines 
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) + 
  stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02', 
              span = 0.25, n = 814)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'

fit_bothb
##   [1] 12.62134 12.61683 12.61241 12.60807 12.60381 12.59965 12.59556 12.59156
##   [9] 12.58765 12.58382 12.58008 12.57641 12.57284 12.56934 12.56593 12.56260
##  [17] 12.55935 12.55619 12.55310 12.55010 12.54718 12.54434 12.54158 12.53890
##  [25] 12.53630 12.53378 12.53134 12.52898 12.52669 12.52449 12.52236 12.52032
##  [33] 12.51835 12.51645 12.51464 12.51290 12.51124 12.50965 12.50814 12.50671
##  [41] 12.50535 12.50406 12.50286 12.50173 12.50068 12.49972 12.49884 12.49804
##  [49] 12.49733 12.49671 12.49617 12.49571 12.49534 12.49506 12.49487 12.49476
##  [57] 12.49474 12.49481 12.49496 12.49521 12.49554 12.49597 12.49648 12.49709
##  [65] 12.49778 12.49857 12.49944 12.50041 12.50147 12.50262 12.50387 12.50521
##  [73] 12.50664 12.50817 12.50979 12.51150 12.51331 12.51522 12.51722 12.51932
##  [81] 12.52151 12.52380 12.52619 12.52868 12.53126 12.53403 12.53706 12.54035
##  [89] 12.54387 12.54763 12.55162 12.55582 12.56022 12.56482 12.56960 12.57456
##  [97] 12.57968 12.58496 12.59038 12.59594 12.60163 12.60743 12.61335 12.61935
## [105] 12.62545 12.63162 12.63786 12.64416 12.65050 12.65689 12.66330 12.66974
## [113] 12.67618 12.68262 12.68905 12.69546 12.70184 12.70819 12.71448 12.72071
## [121] 12.72688 12.73297 12.73897 12.74487 12.75066 12.75634 12.76188 12.76729
## [129] 12.77308 12.77970 12.78706 12.79508 12.80365 12.81269 12.82210 12.83180
## [137] 12.84170 12.85170 12.86171 12.87163 12.88139 12.89088 12.90002 12.90872
## [145] 12.91687 12.92440 12.93121 12.93721 12.94230 12.94806 12.95600 12.96593
## [153] 12.97766 12.99100 13.00577 13.02178 13.03884 13.05676 13.07536 13.09445
## [161] 13.11384 13.13334 13.15277 13.17194 13.19067 13.20875 13.22601 13.24227
## [169] 13.25732 13.27099 13.28308 13.29342 13.30181 13.30806 13.31199 13.31439
## [177] 13.31621 13.31744 13.31810 13.31820 13.31774 13.31675 13.31523 13.31319
## [185] 13.31064 13.30759 13.30406 13.30005 13.29557 13.29063 13.28525 13.27944
## [193] 13.27320 13.26654 13.25949 13.25204 13.24420 13.23600 13.22743 13.21851
## [201] 13.20925 13.19966 13.18975 13.17954 13.16902 13.15688 13.14195 13.12443
## [209] 13.10455 13.08252 13.05856 13.03289 13.00573 12.97729 12.94779 12.91744
## [217] 12.88648 12.85510 12.82354 12.79201 12.76072 12.72989 12.69975 12.67051
## [225] 12.64238 12.61558 12.59034 12.56686 12.54538 12.52609 12.50923 12.49304
## [233] 12.47573 12.45742 12.43827 12.41839 12.39794 12.37704 12.35583 12.33445
## [241] 12.31304 12.29173 12.27066 12.24997 12.22979 12.21025 12.19150 12.17368
## [249] 12.15691 12.14134 12.12710 12.11432 12.10333 12.09421 12.08683 12.08102
## [257] 12.07661 12.07346 12.07140 12.07027 12.06992 12.07018 12.07090 12.07193
## [265] 12.07309 12.07423 12.07520 12.07583 12.07597 12.07545 12.07412 12.07183
## [273] 12.06840 12.06368 12.05752 12.05145 12.04701 12.04403 12.04233 12.04176
## [281] 12.04214 12.04330 12.04507 12.04729 12.04978 12.05238 12.05491 12.05722
## [289] 12.05912 12.06045 12.06104 12.06073 12.05934 12.05670 12.05264 12.04701
## [297] 12.03992 12.03171 12.02245 12.01225 12.00120 11.98939 11.97692 11.96388
## [305] 11.95038 11.93649 11.92232 11.90795 11.89350 11.87904 11.86467 11.85050
## [313] 11.83660 11.82308 11.81004 11.79755 11.78573 11.77466 11.76444 11.75516
## [321] 11.74692 11.73981 11.73189 11.72136 11.70853 11.69371 11.67721 11.65933
## [329] 11.64039 11.62070 11.60055 11.58027 11.56015 11.54052 11.52167 11.50392
## [337] 11.48757 11.47294 11.46033 11.45005 11.44241 11.43772 11.43628 11.43705
## [345] 11.43875 11.44133 11.44475 11.44898 11.45399 11.45972 11.46614 11.47322
## [353] 11.48092 11.48919 11.49801 11.50732 11.51710 11.52730 11.53789 11.54882
## [361] 11.56007 11.57158 11.58333 11.59528 11.60738 11.61960 11.63344 11.65030
## [369] 11.66992 11.69208 11.71655 11.74308 11.77144 11.80139 11.83271 11.86515
## [377] 11.89848 11.93246 11.96687 12.00145 12.03599 12.07023 12.10396 12.13693
## [385] 12.16890 12.19964 12.22892 12.25650 12.28215 12.30563 12.32670 12.34513
## [393] 12.36318 12.38312 12.40474 12.42783 12.45217 12.47756 12.50377 12.53060
## [401] 12.55783 12.58525 12.61265 12.63981 12.66653 12.69258 12.71776 12.74185
## [409] 12.76465 12.78593 12.80548 12.82310 12.83857 12.85167 12.86220 12.87111
## [417] 12.87948 12.88732 12.89461 12.90137 12.90757 12.91323 12.91832 12.92286
## [425] 12.92683 12.93023 12.93306 12.93531 12.93698 12.93807 12.93856 12.93847
## [433] 12.93777 12.93647 12.93457 12.93205 12.92767 12.92033 12.91025 12.89768
## [441] 12.88283 12.86594 12.84725 12.82699 12.80538 12.78265 12.75905 12.73480
## [449] 12.71013 12.68527 12.66046 12.63592 12.61189 12.58860 12.56628 12.54517
## [457] 12.52548 12.50747 12.49134 12.47735 12.46571 12.45667 12.44776 12.43654
## [465] 12.42328 12.40825 12.39171 12.37394 12.35519 12.33573 12.31583 12.29577
## [473] 12.27579 12.25617 12.23718 12.21909 12.20215 12.18664 12.17282 12.16096
## [481] 12.15133 12.14419 12.13980 12.13711 12.13485 12.13302 12.13163 12.13065
## [489] 12.13010 12.12996 12.13024 12.13092 12.13200 12.13349 12.13537 12.13764
## [497] 12.14030 12.14334 12.14676 12.15056 12.15472 12.15925 12.16415 12.16940
## [505] 12.17500 12.18096 12.18879 12.19986 12.21391 12.23066 12.24987 12.27126
## [513] 12.29457 12.31954 12.34591 12.37341 12.40179 12.43077 12.46010 12.48951
## [521] 12.51873 12.54752 12.57560 12.60271 12.62859 12.65297 12.67559 12.69620
## [529] 12.71452 12.73029 12.74326 12.75315 12.76201 12.77197 12.78292 12.79474
## [537] 12.80733 12.82056 12.83432 12.84850 12.86299 12.87766 12.89241 12.90712
## [545] 12.92168 12.93597 12.94989 12.96330 12.97611 12.98819 12.99944 13.00974
## [553] 13.01897 13.02702 13.03377 13.03912 13.04294 13.04513 13.04557 13.04414
## [561] 13.04074 13.03524 13.02676 13.01469 12.99939 12.98117 12.96038 12.93736
## [569] 12.91244 12.88596 12.85825 12.82964 12.80049 12.77111 12.74185 12.71304
## [577] 12.68503 12.65814 12.63271 12.60907 12.58758 12.56855 12.55233 12.53596
## [585] 12.51646 12.49409 12.46912 12.44180 12.41240 12.38118 12.34842 12.31437
## [593] 12.27929 12.24346 12.20713 12.17057 12.13404 12.09781 12.06214 12.02729
## [601] 11.99354 11.96114 11.93035 11.90145 11.87469 11.85034 11.82866 11.80992
## [609] 11.79438 11.78026 11.76566 11.75069 11.73546 11.72009 11.70469 11.68937
## [617] 11.67424 11.65941 11.64499 11.63110 11.61784 11.60533 11.59367 11.58298
## [625] 11.57337 11.56495 11.55784 11.55214 11.54796 11.54541 11.54495 11.54682
## [633] 11.55086 11.55690 11.56476 11.57428 11.58529 11.59762 11.61111 11.62557
## [641] 11.64084 11.65676 11.67315 11.68984 11.70667 11.72347 11.74005 11.75627
## [649] 11.77194 11.78691 11.80099 11.81401 11.82582 11.83812 11.85261 11.86912
## [657] 11.88748 11.90752 11.92908 11.95198 11.97605 12.00113 12.02705 12.05362
## [665] 12.08069 12.10809 12.13564 12.16318 12.19053 12.21753 12.24400 12.26978
## [673] 12.29470 12.31859 12.34127 12.36258 12.38235 12.40040 12.41658 12.43200
## [681] 12.44786 12.46410 12.48067 12.49752 12.51458 12.53179 12.54911 12.56646
## [689] 12.58381 12.60108 12.61823 12.63519 12.65191 12.66833 12.68439 12.70004
## [697] 12.71522 12.72988 12.74395 12.75738 12.77011 12.78208 12.79337 12.80409
## [705] 12.81428 12.82398 12.83323 12.84207 12.85055 12.85869 12.86655 12.87415
## [713] 12.88153 12.88875 12.89583 12.90281 12.90974 12.91666 12.92359 12.93059
## [721] 12.93769 12.94493 12.95236 12.95988 12.96738 12.97485 12.98227 12.98963
## [729] 12.99691 13.00410 13.01118 13.01814 13.02497 13.03165 13.03816 13.04449
## [737] 13.05063 13.05657 13.06228 13.06775 13.07298 13.07793 13.08261 13.08699
## [745] 13.09106 13.09481 13.09822 13.10127 13.10396 13.10638 13.10863 13.11071
## [753] 13.11262 13.11434 13.11588 13.11722 13.11837 13.11931 13.12005 13.12058
## [761] 13.12089 13.12097 13.12083 13.12046 13.11985 13.11899 13.11789 13.11654
## [769] 13.11493 13.11305 13.11094 13.10861 13.10607 13.10331 13.10034 13.09716
## [777] 13.09376 13.09014 13.08631 13.08226 13.07800 13.07351 13.06881 13.06389
## [785] 13.05875 13.05340 13.04782 13.04202 13.03600 13.02976 13.02329 13.01660
## [793] 13.00966 13.00249 12.99507 12.98742 12.97954 12.97142 12.96306 12.95448
## [801] 12.94566 12.93661 12.92734 12.91784 12.90811 12.89817 12.88799 12.87760
## [809] 12.86699 12.85616 12.84511 12.83384 12.82236 12.81067
#assign fits to a vector
both_trendb <- fit_bothb

#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax

#reassign dataframes (just to be safe)
work_bothb <- wrfb_both

#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date

#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
  plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
                    data = smooth_frame_bothb,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothb,
                                  '</br> Median Log Copies: ', round(both_trendb, digits = 2)),
                    line = list(color = '#D95F02', size = 8, opacity = 0.65),
                    showlegend = FALSE) %>%
     layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
                    showlegend = FALSE,
                    opacity = 0.25,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
                                  '</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
                                  '</br> Min Log Copies: ', round(both_yminb, digits = 2)),
                    name = "",
                    fillcolor = '#D95F02',
                    line = list(color = '#D95F02')) %>%
                layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies", 
                                 showline = TRUE,
                                 automargin = TRUE)) %>%
                layout(xaxis = list(title = "Date")) %>%
                layout(title = "WRF B") %>%
  plotly::add_markers(x = ~date, y = ~log_total_copies_both,
                      data = wrfb_both,
                       hoverinfo = "text",
                       showlegend = FALSE,
                       text = ~paste('</br> Date: ', date, 
                                     '</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
                       marker = list(color = '#D95F02', size = 6, opacity = 0.65))

p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")

#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************

extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) + 
  stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A', 
              span = 0.25, n = 814)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'

fit_bothc
##   [1] 12.05876 12.05187 12.04507 12.03838 12.03179 12.02529 12.01890 12.01260
##   [9] 12.00640 12.00029 11.99428 11.98836 11.98254 11.97681 11.97117 11.96563
##  [17] 11.96017 11.95481 11.94954 11.94435 11.93925 11.93424 11.92932 11.92449
##  [25] 11.91974 11.91507 11.91049 11.90599 11.90158 11.89724 11.89299 11.88882
##  [33] 11.88473 11.88072 11.87679 11.87294 11.86916 11.86546 11.86184 11.85829
##  [41] 11.85482 11.85142 11.84809 11.84484 11.84165 11.83854 11.83550 11.83253
##  [49] 11.82963 11.82680 11.82405 11.82140 11.81885 11.81639 11.81404 11.81179
##  [57] 11.80964 11.80759 11.80564 11.80380 11.80205 11.80042 11.79888 11.79745
##  [65] 11.79612 11.79490 11.79378 11.79277 11.79187 11.79107 11.79038 11.78980
##  [73] 11.78932 11.78896 11.78870 11.78855 11.78852 11.78859 11.78877 11.78907
##  [81] 11.78948 11.79000 11.79063 11.79137 11.79223 11.79320 11.79429 11.79549
##  [89] 11.79681 11.79824 11.79979 11.80146 11.80324 11.80513 11.80712 11.80923
##  [97] 11.81145 11.81379 11.81624 11.81880 11.82149 11.82429 11.82722 11.83027
## [105] 11.83345 11.83675 11.84017 11.84373 11.84742 11.85123 11.85519 11.85927
## [113] 11.86349 11.86785 11.87235 11.87698 11.88176 11.88669 11.89175 11.89696
## [121] 11.90232 11.90783 11.91349 11.91930 11.92527 11.93139 11.93766 11.94410
## [129] 11.95069 11.95744 11.96435 11.97143 11.97867 11.98725 11.99818 12.01123
## [137] 12.02617 12.04279 12.06084 12.08011 12.10037 12.12138 12.14293 12.16479
## [145] 12.18672 12.20851 12.22991 12.25072 12.27069 12.28961 12.30724 12.32336
## [153] 12.33774 12.35015 12.36284 12.37804 12.39556 12.41517 12.43667 12.45984
## [161] 12.48447 12.51035 12.53726 12.56500 12.59336 12.62211 12.65105 12.67997
## [169] 12.70864 12.73688 12.76445 12.79114 12.81675 12.84107 12.86388 12.88496
## [177] 12.90411 12.92112 12.93576 12.94784 12.95714 12.96344 12.96734 12.96962
## [185] 12.97037 12.96966 12.96757 12.96419 12.95960 12.95387 12.94709 12.93933
## [193] 12.93068 12.92122 12.91102 12.90017 12.88874 12.87683 12.86450 12.85184
## [201] 12.83893 12.82584 12.81267 12.79948 12.78636 12.77340 12.76066 12.74823
## [209] 12.73619 12.72463 12.71156 12.69518 12.67578 12.65364 12.62907 12.60236
## [217] 12.57379 12.54368 12.51230 12.47995 12.44694 12.41354 12.38006 12.34679
## [225] 12.31402 12.28205 12.25116 12.22167 12.19385 12.16801 12.14443 12.12341
## [233] 12.10525 12.08812 12.07008 12.05124 12.03170 12.01156 11.99094 11.96994
## [241] 11.94866 11.92721 11.90570 11.88424 11.86293 11.84187 11.82118 11.80095
## [249] 11.78130 11.76233 11.74414 11.72685 11.71056 11.69537 11.68128 11.66814
## [257] 11.65590 11.64449 11.63385 11.62391 11.61460 11.60587 11.59764 11.58985
## [265] 11.58244 11.57534 11.56849 11.56182 11.55526 11.54876 11.54224 11.53564
## [273] 11.52890 11.52196 11.51474 11.50718 11.49922 11.49079 11.48183 11.47227
## [281] 11.46291 11.45455 11.44710 11.44046 11.43457 11.42931 11.42462 11.42041
## [289] 11.41658 11.41305 11.40973 11.40654 11.40339 11.40020 11.39687 11.39332
## [297] 11.38947 11.38522 11.38049 11.37519 11.36924 11.36228 11.35410 11.34483
## [305] 11.33461 11.32355 11.31179 11.29947 11.28671 11.27364 11.26039 11.24709
## [313] 11.23388 11.22087 11.20822 11.19603 11.18445 11.17360 11.16361 11.15462
## [321] 11.14675 11.14014 11.13491 11.13120 11.12734 11.12172 11.11457 11.10611
## [329] 11.09657 11.08617 11.07513 11.06368 11.05204 11.04043 11.02907 11.01820
## [337] 11.00803 10.99879 10.99069 10.98397 10.97885 10.97555 10.97429 10.97529
## [345] 10.97879 10.98465 10.99251 11.00226 11.01376 11.02690 11.04154 11.05757
## [353] 11.07486 11.09328 11.11272 11.13305 11.15414 11.17587 11.19812 11.22077
## [361] 11.24368 11.26674 11.28982 11.31280 11.33555 11.35795 11.37988 11.40121
## [369] 11.42181 11.44157 11.46036 11.47806 11.49663 11.51796 11.54177 11.56776
## [377] 11.59568 11.62522 11.65613 11.68810 11.72088 11.75417 11.78770 11.82119
## [385] 11.85435 11.88692 11.91860 11.94913 11.97821 12.00557 12.03094 12.05403
## [393] 12.07455 12.09224 12.10891 12.12646 12.14477 12.16369 12.18310 12.20287
## [401] 12.22286 12.24293 12.26297 12.28282 12.30237 12.32147 12.34000 12.35782
## [409] 12.37480 12.39081 12.40571 12.41937 12.43165 12.44244 12.45158 12.45949
## [417] 12.46667 12.47317 12.47900 12.48420 12.48881 12.49286 12.49638 12.49940
## [425] 12.50196 12.50408 12.50580 12.50716 12.50818 12.50890 12.50934 12.50955
## [433] 12.50955 12.50938 12.50907 12.50865 12.50727 12.50412 12.49935 12.49307
## [441] 12.48541 12.47650 12.46648 12.45545 12.44357 12.43094 12.41770 12.40398
## [449] 12.38990 12.37559 12.36118 12.34680 12.33257 12.31863 12.30509 12.29209
## [457] 12.27975 12.26820 12.25758 12.24800 12.23959 12.23249 12.22493 12.21523
## [465] 12.20363 12.19035 12.17564 12.15973 12.14285 12.12523 12.10712 12.08875
## [473] 12.07034 12.05215 12.03439 12.01731 12.00114 11.98611 11.97246 11.96042
## [481] 11.95024 11.94213 11.93635 11.93166 11.92673 11.92162 11.91639 11.91109
## [489] 11.90578 11.90052 11.89536 11.89036 11.88559 11.88109 11.87693 11.87316
## [497] 11.86983 11.86702 11.86476 11.86313 11.86218 11.86196 11.86254 11.86397
## [505] 11.86630 11.86960 11.87462 11.88193 11.89137 11.90274 11.91586 11.93056
## [513] 11.94665 11.96394 11.98226 12.00142 12.02124 12.04154 12.06213 12.08283
## [521] 12.10347 12.12385 12.14379 12.16311 12.18164 12.19918 12.21556 12.23058
## [529] 12.24408 12.25586 12.26575 12.27356 12.28081 12.28909 12.29831 12.30837
## [537] 12.31917 12.33063 12.34266 12.35515 12.36802 12.38118 12.39454 12.40799
## [545] 12.42145 12.43482 12.44801 12.46094 12.47350 12.48561 12.49716 12.50808
## [553] 12.51826 12.52761 12.53605 12.54347 12.54979 12.55491 12.55874 12.56118
## [561] 12.56215 12.56156 12.55927 12.55534 12.54989 12.54309 12.53507 12.52598
## [569] 12.51595 12.50515 12.49371 12.48177 12.46948 12.45699 12.44444 12.43197
## [577] 12.41973 12.40786 12.39651 12.38583 12.37595 12.36702 12.35919 12.35056
## [585] 12.33929 12.32559 12.30967 12.29175 12.27205 12.25076 12.22812 12.20433
## [593] 12.17960 12.15415 12.12819 12.10194 12.07560 12.04940 12.02355 11.99825
## [601] 11.97373 11.95019 11.92785 11.90693 11.88763 11.87017 11.85476 11.84163
## [609] 11.83097 11.82140 11.81144 11.80117 11.79067 11.78003 11.76933 11.75864
## [617] 11.74805 11.73764 11.72749 11.71768 11.70830 11.69943 11.69114 11.68352
## [625] 11.67666 11.67062 11.66550 11.66137 11.65832 11.65643 11.65616 11.65782
## [633] 11.66125 11.66632 11.67287 11.68076 11.68982 11.69992 11.71090 11.72262
## [641] 11.73492 11.74766 11.76068 11.77384 11.78699 11.79998 11.81266 11.82487
## [649] 11.83648 11.84732 11.85726 11.86614 11.87381 11.88151 11.89050 11.90067
## [657] 11.91193 11.92416 11.93726 11.95113 11.96566 11.98075 11.99628 12.01217
## [665] 12.02829 12.04455 12.06084 12.07705 12.09309 12.10884 12.12420 12.13907
## [673] 12.15334 12.16690 12.17966 12.19150 12.20232 12.21202 12.22048 12.22837
## [681] 12.23637 12.24446 12.25263 12.26084 12.26909 12.27734 12.28558 12.29378
## [689] 12.30192 12.30998 12.31794 12.32577 12.33345 12.34097 12.34830 12.35541
## [697] 12.36229 12.36891 12.37526 12.38131 12.38703 12.39241 12.39718 12.40114
## [705] 12.40436 12.40693 12.40890 12.41037 12.41139 12.41206 12.41243 12.41259
## [713] 12.41262 12.41258 12.41255 12.41260 12.41282 12.41326 12.41402 12.41516
## [721] 12.41677 12.41890 12.42164 12.42477 12.42799 12.43131 12.43471 12.43816
## [729] 12.44167 12.44520 12.44876 12.45233 12.45589 12.45942 12.46292 12.46637
## [737] 12.46976 12.47308 12.47630 12.47942 12.48242 12.48529 12.48801 12.49058
## [745] 12.49297 12.49517 12.49718 12.49897 12.50053 12.50194 12.50328 12.50456
## [753] 12.50577 12.50692 12.50799 12.50899 12.50992 12.51077 12.51154 12.51224
## [761] 12.51285 12.51338 12.51383 12.51420 12.51448 12.51466 12.51476 12.51477
## [769] 12.51468 12.51450 12.51424 12.51389 12.51346 12.51295 12.51236 12.51169
## [777] 12.51094 12.51012 12.50921 12.50823 12.50716 12.50602 12.50480 12.50350
## [785] 12.50212 12.50067 12.49914 12.49753 12.49584 12.49407 12.49223 12.49030
## [793] 12.48827 12.48615 12.48393 12.48162 12.47922 12.47672 12.47413 12.47145
## [801] 12.46869 12.46583 12.46289 12.45985 12.45674 12.45353 12.45024 12.44687
## [809] 12.44342 12.43988 12.43626 12.43256 12.42878 12.42492
#assign fits to a vector
both_trendc <- fit_bothc

#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax

#reassign dataframes (just to be safe)
work_bothc <- wrfc_both

#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date

#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
  plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
                    data = smooth_frame_bothc,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothc,
                                  '</br> Median Log Copies: ', round(both_trendc, digits = 2)),
                    line = list(color = '#E7298A', size = 8, opacity = 0.65),
                    showlegend = FALSE) %>%
     layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
                    showlegend = FALSE,
                    opacity = 0.25,
                    hoverinfo = "text",
                    text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
                                  '</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
                                  '</br> Min Log Copies: ', round(both_yminc, digits = 2)),
                    name = "",
                    fillcolor = '#E7298A',
                    line = list(color = '#E7298A')) %>%
                layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies", 
                                 showline = TRUE,
                                 automargin = TRUE)) %>%
                layout(xaxis = list(title = "Date")) %>%
                layout(title = "WRF C") %>%
  plotly::add_markers(x = ~date, y = ~log_total_copies_both,
                      data = wrfc_both,
                       hoverinfo = "text",
                       showlegend = FALSE,
                       text = ~paste('</br> Date: ', date, 
                                     '</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
                       marker = list(color = '#E7298A', size = 6, opacity = 0.65))

p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")

save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")

save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")